package flc.ast.activity;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;

import android.os.Bundle;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;

import java.util.ArrayList;
import java.util.List;

import flc.ast.BaseAc;
import flc.ast.R;
import flc.ast.adapter.TypeAdapter;
import flc.ast.bean.MyPassKindBean;
import flc.ast.databinding.ActivityTypeBinding;
import flc.ast.utils.AppSpUtils;

public class TypeActivity extends BaseAc<ActivityTypeBinding> {

    private TypeAdapter typeAdapter;
    private List<MyPassKindBean> listShow = new ArrayList<>();

    @Override
    protected int onCreate() {
        return R.layout.activity_type;
    }

    @Override
    protected void initView() {
        mDataBinding.ivTypeBack.setOnClickListener(v -> onBackPressed());

        mDataBinding.rvTypeList.setLayoutManager(new LinearLayoutManager(mContext));
        typeAdapter=new TypeAdapter();
        mDataBinding.rvTypeList.setAdapter(typeAdapter);
        typeAdapter.setOnItemClickListener(this);
    }

    @Override
    protected void onItemClickCallback(@NonNull BaseQuickAdapter<?, ?> adapter, @NonNull View view, int position) {
        AddPasswordActivity.kindBean=typeAdapter.getItem(position);
        finish();
    }

    @Override
    protected void initData() {
        getData();
    }

    //获取记录
    private void getData() {
        listShow.clear();
        List<MyPassKindBean> listSp = AppSpUtils.getPasswordList();
        listShow.addAll(listSp);
        typeAdapter.setList(listShow);
    }

}